package com.beyond.market.orders.controller;

import com.beyond.market.orders.domain.Orders;
import com.beyond.market.orders.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

@Controller
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    @RequestMapping("/text")
    @ResponseBody
    public String text(){
        Orders orders = new Orders();
        orders.setUserId(1);
        orders.setOrderPrice(100.0);
        try {
            Integer save = ordersService.save(orders);
            return save.toString();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }
    @RequestMapping("/listByUserId")
    public String listByUserId(@RequestParam("id") Integer id, Map map2){
        try {
            List<Orders> listAll = ordersService.listByUserId(id);
            map2.put("listAll",listAll);
        } catch (SQLException e) {
            e.printStackTrace();

        }
        return "orders";
    }

}
